package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.Scheduler.DmScheduler;
import com.hdax.dm.beans.Scheduler.DmSchedulerSeatPrice;
import com.hdax.dm.dto.getScheduleDto;
import com.hdax.dm.dto.getTimePlanDto;
import com.hdax.dm.mappers.getTimePlanMapper;
import com.hdax.dm.mapstucts.getScheduleDtoMapper;
import com.hdax.dm.mapstucts.getTimePlanDtoMapper;
import com.hdax.dm.service.DmSchedulerSeatPriceService;
import com.hdax.dm.service.DmSchedulerSeatService;
import com.hdax.dm.service.DmSchedulerService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DmSchedulerServiceImpl extends ServiceImpl<getTimePlanMapper, DmScheduler> implements DmSchedulerService {

    @Autowired
    private getTimePlanDtoMapper schedulerDtoMapper;

    @Autowired
    private getScheduleDtoMapper getScheduleDtoMapper;

    @Autowired
    private DmSchedulerSeatService getScheduleService;

    @Autowired
    private DmSchedulerSeatPriceService getPriceService;

    @Override
    public CommonResponse<List<getTimePlanDto>> getComments(Map<String,Integer> params) {
        Integer id = params.get("itemId");
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("itemid",id);
        List<DmScheduler> sc = baseMapper.selectList(queryWrapper);
        List<getTimePlanDto> dto = schedulerDtoMapper.toTargetList(sc);
        return ResponseUtil.returnSuccess(dto);
    }

    @Override
    public CommonResponse<getScheduleDto> getSchedule(Map<String, Integer> params) {

        getScheduleDto seatInfodtos = new getScheduleDto();

        Integer cinemaId = params.get("cinemaId");
        Integer id = params.get("scheduleId");

        seatInfodtos.setCinemaId(cinemaId.longValue());
        seatInfodtos.setScheduleId(id.longValue());

        List<getScheduleDto.seatInfo> seatInfo = getScheduleDtoMapper.toseatInfoList(getScheduleService.DmSchedulerSeat(id));


        for (getScheduleDto.seatInfo info : seatInfo) {
            if (info.getAreaLevel().equals("1")) {
                info.setAreaLevel("A");
            }else if (info.getAreaLevel().equals("2")) {
                info.setAreaLevel("B");
            }else if (info.getAreaLevel().equals("3")) {
                info.setAreaLevel("C");
            }
        }

        List<getScheduleDto.seatPrice> seatPrice = getScheduleDtoMapper.toseatPriceList(getPriceService.DmSchedulerSeatPrice(id));

        List<DmSchedulerSeatPrice> lists = getPriceService.DmSchedulerSeatPrice(id);
        for (int i = 0; i < lists.size(); i++) {
            if (lists.get(i).getAreaLevel()==1){
                seatPrice.get(i).setAreaLevelName("A");
            }else if (lists.get(i).getAreaLevel()==2){
                seatPrice.get(i).setAreaLevelName("B");
            }else if (lists.get(i).getAreaLevel()==3){
                seatPrice.get(i).setAreaLevelName("C");
            }
        }

        seatInfodtos.setSeatInfoList(seatInfo);
        seatInfodtos.setSeatPriceList(seatPrice);

        return ResponseUtil.returnSuccess(seatInfodtos);
    }


}
